from jsonpath_rw import parse,jsonpath

def get_key_from_data(key,data,val=None):
    # 定义匹配规则
    json_expr=parse(key)
    re=json_expr.find(data)
    # json_expr.update(data,val)
    # result=json_expr.find(data)
    # retest=json_expr.u
    # resultt=json_expr.update(date,)
    # [match.value for match in male][0]
    return [match.value for match in re]

if __name__ == '__main__':
    # key="msg"
    # key="data[*].uid"
    val="88"
    key="$..uid"
    data={"code":"00","msg":"success","data":[
        {"uid":"1","name":"zs","age":11},
        # {"uid": "2", "name": "ls", "age": 12},
        # {"uid": "3", "name": "ww", "age": 13}
    ]}
    print(get_key_from_data(key,data))